package com.stony.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by ShiHui on 2014/6/19.
 */
@Aspect
//@Component
public class MyInterceptor {



    @Pointcut("execution(* com.stony.aspects.*.save*(..))")
    private void anyMethod() {

    }
    @Pointcut("execution(* com.stony.aspects.*.update*(..))")
    private void doMethod() {

    }




    @Before("anyMethod()&&args(name)")
    public void doAccessCheck(String name) {
        System.out.println(name);
        System.out.println("前置通知");
    }

    /* @AfterReturning("anyMethod()") */
    @AfterReturning("anyMethod()")
    public void doAfter() {
        System.out.println("后置通知");
    }

    @After("anyMethod()")
    public void after() {
        System.out.println("最终通知");
    }

    @AfterThrowing("anyMethod()")
    public void doAfterThrow() {
        System.out.println("例外通知");
    }

    @Around("anyMethod()")
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("进入环绕通知");
        Object object = pjp.proceed();// 执行该方法
        System.out.println("退出方法");
        return object;
    }

    @Around("doMethod()")
    public Object doBasic(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("进入环绕通知...");
        Object object = pjp.proceed();// 执行该方法
        System.out.println("退出方法...");
        return object;
    }
}
